CentOS 6
Sponsored Link

DRBD : Configure
2015/03/10
 
Configure DRBD after installing.
This example is based on the environment like follows.
+----------------------+          |          +----------------------+
| [   DRBD Server#1  ] |10.0.0.30 | 10.0.0.31| [   DRBD Server#2  ] |
|   drbd01.srv.world   +----------+----------+   drbd02.srv.world   |
|                      |                     |                      |
+----------------------+                     +----------------------+

It's necessarry the server you'd like to install DRBD has free block-device.
This example shows to configure to use a block-device "/dev/vg_r0/lv_r0".
[1] Configure DRBD on both Hosts.
[root@drbd01 ~]#
vi /etc/drbd.d/global_common.conf
# add follows in the disk section ( detach disk if IO errors happen )

disk {
   on-io-error detach;
[root@drbd01 ~]#
vi /etc/drbd.d/r0.res
# create new

resource r0 {
   
# DRBD device

    device /dev/drbd0;
   
# block device

    disk /dev/vg_r0/lv_r0;
    meta-disk internal;
    on drbd01.srv.world {
       
# IP address:port

        address 10.0.0.30:7788;
    }
    on drbd02.srv.world {
        address 10.0.0.31:7788;
    }
}
# load module

[root@drbd01 ~]#
modprobe drbd

[root@drbd01 ~]#
lsmod | grep drbd

drbd                  343511  0
libcrc32c               1246  1 drbd

# create DRBD resource

[root@drbd01 ~]#
drbdadm create-md r0
  --==  Thank you for participating in the global usage survey  ==--
The server's response is:
...
...
[need to type 'yes' to confirm]
yes

initializing activity log
NOT initializing bitmap
Writing meta data...
New drbd meta data block successfully created.
success

[root@drbd01 ~]#
/etc/rc.d/init.d/drbd start

Starting DRBD resources: [
     create res: r0
   prepare disk: r0
    adjust disk: r0drbd r0: Starting worker thread (from drbdsetup-84 [17259])
...
...
To abort waiting enter 'yes' [ 18]:
yes
[root@drbd01 ~]#
chkconfig drbd on

[root@drbd01 ~]#
echo "/sbin/modprobe drbd" >> /etc/rc.local

[2] After configuring on both Hosts, sync data on a Host.
# current status is "Secondary/Secondary"

[root@drbd01 ~]#
cat /proc/drbd

version: 8.4.5 (api:1/proto:86-101)
GIT-hash: 1d360bde0e095d495786eaeb2a1ac76888e4db96 build by root@drbd01.srv.world, 2015-03-11 17:20:57
 0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r-----
    ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:83879388

# get primary role and sync data

[root@drbd01 ~]#
drbdadm -- --overwrite-data-of-peer primary r0
# start sync

[root@drbd01 ~]#
cat /proc/drbd

version: 8.4.5 (api:1/proto:86-101)
GIT-hash: 1d360bde0e095d495786eaeb2a1ac76888e4db96 build by root@drbd01.srv.world, 2015-03-11 17:20:57
 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----
    ns:129216 nr:0 dw:0 dr:129880 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:83750172
        [>....................] sync'ed:  0.2% (81784/81912)M
        finish: 3:03:05 speed: 7,600 (7,600) K/sec

# after syncing, the status turns like follows

[root@drbd01 ~]#
cat /proc/drbd

version: 8.4.5 (api:1/proto:86-101)
GIT-hash: 1d360bde0e095d495786eaeb2a1ac76888e4db96 build by root@drbd01.srv.world, 2015-03-11 17:20:57
 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
    ns:83879388 nr:0 dw:0 dr:83880052 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[3] It's OK to configure DRBD, create file system on DRBD device and mount it to use.
[root@drbd01 ~]#
mkfs.ext4 /dev/drbd0

[root@drbd01 ~]#
mkdir /drbd_disk

[root@drbd01 ~]#
mount /dev/drbd0 /drbd_disk

[root@drbd01 ~]#
df -hT

Filesystem           Type   Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                     ext4    16G  1.4G   14G  10% /
tmpfs                tmpfs  1.9G     0  1.9G   0% /dev/shm
/dev/vda1            ext4   477M  119M  333M  27% /boot
/dev/drbd0           ext4    79G   56M   75G   1% /drbd_disk

# try to create a test file

[root@drbd01 ~]#
touch /drbd_disk/test.txt

[root@drbd01 ~]#
ll /drbd_disk

total 16
drwx------ 2 root root 16384 Mar 12 12:01 lost+found
-rw-r--r-- 1 root root     0 Mar 12 12:52 test.txt
[4] To mount DRBD device on the secondary Host, do it like follows.
########### on primary Host ###########

# unmount and get secondary role

[root@drbd01 ~]#
umount /drbd_disk

[root@drbd01 ~]#
drbdadm secondary r0
########### on secondary Host ###########

# get primary role and mount

[root@drbd02 ~]#
drbdadm primary r0

[root@drbd02 ~]#
mount /dev/drbd0 /drbd_disk

[root@drbd02 ~]#
df -hT

Filesystem           Type   Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                     ext4    16G  1.4G   14G  10% /
tmpfs                tmpfs  1.9G     0  1.9G   0% /dev/shm
/dev/vda1            ext4   477M  119M  333M  27% /boot
/dev/drbd0           ext4    79G   56M   75G   1% /drbd_disk
 
Tweet